<?php
if ($_FILES["file"]["error"] > 0)
{
    echo "错误：" . $_FILES["file"]["error"] . "<br>";
}
else
{
    echo "上传文件名: " . $_FILES["file"]["name"] . "<br>";
    echo "文件类型: " . $_FILES["file"]["type"] . "<br>";
    echo "文件大小: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    // echo "文件临时存储的位置: " . $_FILES["file"]["tmp_name"];

    if (file_exists("/opensemanticsearch_doc/" . $_FILES["file"]["name"]))
    {
        echo $_FILES["file"]["name"] . " 文件已经存在或文件名重复。 ";
        // system("opensemanticsearch-index-file "."/opensemanticsearch_doc/" . $_FILES["file"]["name"]);
    }
    else
    {


        // 如果 upload 目录不存在该文件则将文件上传到 upload 目录下
        move_uploaded_file($_FILES["file"]["tmp_name"], "/opensemanticsearch_doc/" . $_FILES["file"]["name"]);
        echo "文件存储在: " . "/opensemanticsearch_doc/" . $_FILES["file"]["name"];
        // system("chmod a+w"."/opensemanticsearch_doc/" . $_FILES["file"]["name"]);
        // system("chmod a+r"."/opensemanticsearch_doc/" . $_FILES["file"]["name"]);

        // system("opensemanticsearch-index-file "."/opensemanticsearch_doc/" . $_FILES["file"]["name"]);
        $_FILES["file"]["name"]=str_replace(" ","%20",$_FILES["file"]["name"]);
        echo $_FILES["file"]["name"];
        $url="http://127.0.0.1:/search-apps/api/index-file?uri="."/opensemanticsearch_doc/" . $_FILES["file"]["name"];
        $html = file_get_contents($url);
        echo "<br>";
        echo $url;
        echo "<br>";
        echo $html;
        echo "添加索引成功";
    }
}
?>